<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        // 创建商品表
        Schema::create('warehouses', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('project_id')->default(0); // 关联项目 ID
            $table->string('title');
            $table->string('content')->default('/');
            $table->decimal('unit_price', 10, 2);
            $table->string('specifications')->default('/')->comment('规格');
            $table->integer('sum')->default(0);
            $table->timestamps();
        });

        // 创建入库表
        Schema::create('warehouses_ins', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('warehouse_id');
            $table->unsignedBigInteger('project_id')->default(0); // 关联项目 ID
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('supplier_id')->default(0)->comment('供应商');
            $table->integer('quantity')->comment('入库数量');
            $table->string('numbers')->comment('批次号');
            $table->string('supplier')->comment('供应商名称');
            $table->dateTime('in_date')->useCurrent();
            $table->string('files')->nullable()->comment('入库单');
            $table->string('remarks')->default('/')->comment('备注');
            $table->string('storage')->default('/')->comment('位置');
            $table->timestamps();
        });

        // 创建出库表
        Schema::create('warehouses_outs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('warehouse_id');
            $table->unsignedBigInteger('project_id')->default(0); // 关联项目 ID
            $table->unsignedBigInteger('user_id');
            $table->integer('quantity')->comment('出库数量');
            $table->dateTime('out_date')->useCurrent();
            $table->string('numbers')->comment('批次号');
            $table->string('files')->nullable()->comment('出库单');
            $table->string('remarks')->default('/')->comment('备注');
            $table->timestamps();
        });

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('warehouses');
        Schema::dropIfExists('warehouses_ins');
        Schema::dropIfExists('warehouses_outs');
    }
};
